<template>
	<view class="">
		<!-- 广告插入 -->
		<adview :title="title" @adfun="adfun"></adview>
		<view class="" v-if="!adShow">
			<nav-tab v-if="!exhibitionId" :nav-index="navIndex" @tabChange="tabChange"></nav-tab>
			<view class="bg-white py-2 px-4"><search-view @search="searchChange" @clear="searchChange('')"></search-view></view>
			<view class="px-2 py-1">
				<view class="bg-white rounded_10 p-2">
					<nav-tab2 :title="title" @contTabChange="contTabChange" @contTabChange2="contTabChange2" @updateChange="updateChange" @hotChange="hotChange"></nav-tab2>
					<view v-if="contList.length < 1" class="p-2 mt-3"><u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty></view>
					<view v-else>
						<live-list :cont-list="contList"></live-list>
						<u-loadmore :status="status" color="#E5E5E5" lineColor="#E5E5E5" dashed line />
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import navTab from '@/components/nav-tab/nav-tab.vue';
import searchView from '@/components/search/search.vue';
import navTab2 from '@/components/nav_tab2/nav_tab2.vue';
import liveList from '@/components/live_list/live_list.vue';
import adview from '@/components/adview/adview.vue';
import { getVideoliveList } from '@/api/home/video/video.js';
export default {
	components: { navTab, searchView, navTab2, liveList, adview },
	data() {
		return {
			searchV: '',
			navIndex: 0,
			title: '', //页面标题
			page: 1,
			pagesize: 10,
			status: 'loadmore',
			suo: true,
			isUpdate: false,
			isHot: false,
			pCatId: 0, //一级分类
			catId: 0, //二级分类id
			contList: [],
			exhibitionId: '', //展会id
			adShow: true
		};
	},
	onReachBottom() {
		if (this.suo) {
			//定义个小锁，当没有数据时锁住suo
			this.status = 'loading';
			this.page = ++this.page;
			setTimeout(() => {
				this.getLive();
			}, 1000);
		}
	},
	onShow() {
		let videoType = uni.getStorageSync('videoType');
		this.exhibitionId = videoType.exhibitionId || '';
		this.navIndex = videoType.navIndex;
		this.title = videoType.title;
		// console.log('videoType', videoType);
		uni.setNavigationBarTitle({
			title: this.title
		});
		if (!videoType) {
			this.getLive();
		}
	},
	onPullDownRefresh() {
		this.reset();
		this.getLive();
	},
	methods: {
		// 广告页
		adfun(val) {
			this.adShow = val;
		},
		// 顶部tab
		tabChange(val, idx) {
			// console.log(val, idx);
			this.navIndex = idx;
			this.title = val;
			uni.setNavigationBarTitle({
				title: val
			});
		},
		reset() {
			this.page = 1;
			this.contList = [];
		},
		searchChange(value) {
			this.searchV = value;
			this.reset();
			this.getLive();
		},
		// 列表tab
		contTabChange(val, idx) {
			console.log(val, idx);
			this.pCatId = val.id;
			this.catId = 0;
			this.reset();
			this.getLive();
		},
		// tab2
		contTabChange2(val, idx) {
			// console.log(val, idx);
			this.catId = val.id;
			this.reset();
			this.getLive();
		},
		// 最近更新
		updateChange(val) {
			this.isUpdate = val ? 1 : 0;
			this.reset();
			this.getLive();
		},
		// 实时热门
		hotChange(val) {
			this.isHot = val ? 1 : 0;
			this.reset();
			this.getLive();
		},
		getLive() {
			let msg = {
				page: this.page,
				pagesize: this.pagesize,
				kw: this.searchV,
				pcat_id: this.pCatId,
				cat_id: this.catId,
				zhanhui_id: this.exhibitionId || '',
				renew: this.isUpdate,
				heat: this.isHot,
				is_recommend: 0
			};
			getVideoliveList(msg).then(res => {
				// console.log("获取列表", res);
				uni.stopPullDownRefresh();
				if (res.code == 0) {
					this.contList.push(...res.data);
					if (res.data.length == 0) {
						this.status = 'nomore';
						this.suo = false;
					} else if (res.data.length < 10) {
						this.status = 'nomore';
						this.suo = false;
					} else {
						this.status = 'loadmore';
						this.suo = true;
					}
				} else {
					console.log('获取列表失败', res.msg);
				}
			});
		}
	}
};
</script>

<style></style>
